/* 
 * Copyright 2014 ShangDao.Ltd  All rights reserved.
 * SiChuan ShangDao.Ltd PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * 
 * @MyBaForeShowAdapter.java  2014年9月12日 下午5:13:46 - Guzhu
 * @author Guzhu
 * @email:muyi126@163.com
 * @version 1.0
 */

package com.android.tiango.baba.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.scsd.tiango.R;
import com.android.tiango.baba.entity.ActivityModel;
import com.android.tiango.baba.util.DensityUtil;
import com.android.tiango.baba.util.TimeToUtil;

public class MyBaForeShowAdapter extends BaseAdapter {

	private ArrayList<ActivityModel> list;
	private Context context;

	private final static int RIGHT = 0;
	private final static int LEFT = 1;

	public MyBaForeShowAdapter(ArrayList<ActivityModel> list, Context context) {
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public ActivityModel getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public int getItemViewType(int position) {
		return position % 2 == 0 ? RIGHT : LEFT;
	}

	@Override
	public int getViewTypeCount() {
		return 2;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		int type = getItemViewType(position);
		ActivityModel model = getItem(position);
		if (null == convertView) {
			if (position == 0) {
				convertView = LayoutInflater.from(context).inflate(
						R.layout.item_active_foreshow_first, null);
			} else {
				convertView = LayoutInflater.from(context).inflate(R.layout.item_active_foreshow,
						null);
			}
			LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, DensityUtil.dip2px(
					context, 40));
			convertView.setLayoutParams(params);
			viewHolder = new ViewHolder(convertView);
			convertView.setTag(viewHolder);
		}
		viewHolder = (ViewHolder) convertView.getTag();
		if (position == 0) {
			viewHolder.tv_time2.setTextColor(context.getResources().getColor(R.color.font_blue));
			viewHolder.iv_iImageView.setBackgroundDrawable(context.getResources().getDrawable(
					R.drawable.blue_point));
		} else {
			viewHolder.tv_time2.setTextColor(context.getResources().getColor(R.color.color_light));
			viewHolder.iv_iImageView.setBackgroundDrawable(context.getResources().getDrawable(
					R.drawable.gray_point));
		}
		switch (type) {
		case RIGHT:
			viewHolder.tv_time1.setVisibility(View.INVISIBLE);
			viewHolder.tv_time2.setVisibility(View.VISIBLE);
			if (null != model) {
				viewHolder.tv_time2.setText(TimeToUtil.getSystemTimeSetFormat(model.getStartTime(),
						TimeToUtil.ACCURATE_TO_SHOW_ACTIVE));
			}
			break;
		case LEFT:
			viewHolder.tv_time1.setVisibility(View.VISIBLE);
			viewHolder.tv_time2.setVisibility(View.INVISIBLE);
			if (null != model) {
				viewHolder.tv_time1.setText(TimeToUtil.getSystemTimeSetFormat(model.getStartTime(),
						TimeToUtil.ACCURATE_TO_SHOW_ACTIVE));
			}
			break;
		default:
			break;
		}

		return convertView;
	}

	private class ViewHolder {
		TextView tv_time1;
		TextView tv_time2;
		ImageView iv_iImageView;

		public ViewHolder(View v) {
			tv_time1 = (TextView) v.findViewById(R.id.tv_time_1);
			tv_time2 = (TextView) v.findViewById(R.id.tv_time_2);
			iv_iImageView = (ImageView) v.findViewById(R.id.iv_Point);
		}

	}

}
